package com.controller;


import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bean.Classification;
import com.service.ClassificationService;

/**
 * @author author : 张鹏
 * @date createTime：2018年1月10日 下午10:46:47
 * @Description: 该类的功能描述
 */
@Controller
@RequestMapping("classification")
public class ClassificationController {
	@Autowired
	private ClassificationService classificationService;

	Classification classification;
	
	List<Classification> classificationList;

	/**
	 * 查询所有菜品类别
	 * @return
	 */
	@RequestMapping("getAllClassification")
	public String getAllclassification(HttpServletRequest request) {
		request.setAttribute("classificationList", classificationService.getAllClassification());
		return "classificationManage";
	}
	
	/**
	 * 查询所有菜品类别
	 * @param returnTo 请求中添加返回路径 jsp
	 * @param request
	 * @return
	 */
	@RequestMapping("getAllClassificationReturnTo")
	public String getAllclassification(String returnTo,HttpServletRequest request) {
		request.setAttribute("classificationList", classificationService.getAllClassification());
		return returnTo;
	}
	
	

	/**
	 * 查询所有菜品类别  ajax
	 * @return
	 */
	@RequestMapping("getAllClassificationAjax")
	@ResponseBody
	public List<Classification> getAllClassificationAjax(HttpServletRequest request) {
		return classificationService.getAllClassification();
	}
	

	/**
	 * 创建新的菜品类别
	 * 
	 * @param classificationName
	 * @return
	 */
	@RequestMapping("createNewClassificationAjax")
	@ResponseBody
	public String createNewclassification(String classificationName) {
		classification = new Classification();
		classification.setClassificationName(classificationName);
		return classificationService.createNewClassification(classification) + "";
	}

	/**
	 * 编辑菜品类别
	 * 
	 * @param classificationId
	 * @param classificationName
	 * @return
	 */
	@RequestMapping("editClassificationAjax")
	@ResponseBody
	public String editClassification(int classificationId, String classificationName) {
		classification = new Classification();
		classification.setClassificationId(classificationId);
		classification.setClassificationName(classificationName);
		return classificationService.editClassification(classification) + "";
	}

	/**
	 * 删除菜品类别
	 * 
	 * @param classificationId
	 * @return
	 */
	@RequestMapping("deleteClassificationAjax")
	@ResponseBody
	public String deleteClassification(int classificationId) {
		return classificationService.deleteClassification(classificationId) + "";
	}

}
